﻿using Microsoft.Extensions.Configuration;

namespace PluginBase
{
    public delegate void DelegateLog(string info);
    public delegate void DelegateUpdateStatusBarInfo(string info);
    public delegate bool DelegateShareResources(Dictionary<string, object> dicObj);
    public delegate Dictionary<string, object> DelegateGetResources(string sourceName);
    public delegate IConfiguration? DelegateGetConfiguration();

    public partial class UserControlBase : UserControl
    {
        public DelegateLog Log;
        /// <summary>
        /// 更新状态栏信息
        /// </summary>
        public DelegateUpdateStatusBarInfo UpdateStatusBarInfo;
        public DelegateShareResources ShareResources;
        public DelegateGetResources GetResources;
        public DelegateGetConfiguration GetConfiguration;

        public UserControlBase()
        {
            InitializeComponent();
        }
        public UserControlBase(string ucName, Icon icon = null)
        {
            InitializeComponent();
            this.ucName = ucName;
            if (icon != null) ucIcon = icon;
        }

        private void UserControlBase_Load(object sender, EventArgs e)
        {
            this.Dock = DockStyle.Fill;
        }

        protected string ucName = "UCName";
        public String UCName
        {
            get
            {
                return ucName;
            }
        }

        protected string ucType = "我的应用";
        public String UCTpye
        {
            get
            {
                return ucType;
            }
        }

        protected string ucVersion = "1.0";
        public String UCVersion
        {
            get
            {
                return ucVersion;
            }
        }

        protected string recommend = "";
        public string Recommend
        {
            get
            {
                return "【" + UCName + "】[" + UCVersion + "]\r\n" + recommend;
            }
        }

        private bool isPrivateUc = false;
        public bool IsPrivateUc
        {
            get
            {
                return isPrivateUc;
            }
            protected set
            {
                isPrivateUc = value;
                if (isPrivateUc) authorized = false;
            }
        }

        protected bool authorized = true;
        /// <summary>
        /// 是否已认证
        /// </summary>
        public bool Authorized
        {
            get
            {
                return authorized;
            }
            set
            {
                authorized = value;
            }
        }

        protected Icon ucIcon = Icon.FromHandle(
                Properties.Resources.JobTools_32x32.ToBitmap().GetHicon()
            );
        public Icon UcIcon
        {
            get
            {
                return ucIcon;
            }
        }

        private Dictionary<string, string> dicTags = new Dictionary<string, string>();
        public Dictionary<string, string> DicTags
        {
            get
            {
                return dicTags;
            }
        }

        /// <summary>
        /// 程序所在目录，以“\”结尾
        /// </summary>
        public string ProgramPath
        {
            get
            {
                return Environment.CurrentDirectory + "\\";
            }
        }
    }
}